package com.hanfengyi.feign.fallback;

import com.hanfengyi.course.domain.CourseType;
import com.hanfengyi.course.temp.CourseNativeSearchQueryBuilder;
import com.hanfengyi.doc.CourseDoc;
import com.hanfengyi.feign.ESFeignClient;
import com.hanfengyi.hrm.AjaxResult;
import com.hanfengyi.hrm.PageList;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * User: Han
 * Date: 2020/2/23
 * Time: 17:21
 * Description:
 */
@Component
public class ESFeignFallbackFactory implements FallbackFactory<ESFeignClient> {
    @Override
    public ESFeignClient create(Throwable throwable) {
        return new ESFeignClient() {
            @Override
            public AjaxResult deleteById(Long id) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false)
                        .setMessage("发生了一点小问题:["+throwable.getMessage()+"]");
            }

            @Override
            public AjaxResult save(CourseDoc courseDoc) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false)
                        .setMessage("发生了一点小问题:["+throwable.getMessage()+"]");
            }

            @Override
            public PageList<CourseType> searchByQuery(CourseNativeSearchQueryBuilder courseNativeSearchQueryBuilder) {
                throwable.printStackTrace();
                return null;
            }
        };
    }
}